package com.itdct.onflow.system.log.schedule

import com.itdct.onflow.core.extend.saveBatch
import com.itdct.onflow.system.log.global.SysApiLogList
import com.itdct.onflow.system.log.mapper.SysApiLogMapper
import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Component

/**
 * @author Zhouwx
 * @date 2025/10/23 16:22:40
 * @version 1.0
 * @description
 */
@Component
class SysApiWriteSchedule(
    val sysApiLogMapper: SysApiLogMapper
) {
    // 使用定时任务每隔30秒执行一次
    @Scheduled(cron = "0/30 * * * * ?")
    fun writeSysApiLog() {
        val apiLogs = SysApiLogList.drainToCollection()
        if (apiLogs.isEmpty()) {
            return
        }
        sysApiLogMapper.saveBatch(apiLogs)
    }

}